#include <stdio.h>
#define true 1
#define false 0
#define head 4
int palace[head][head]={0};
int newX=0,newY=0;
int count=0;

int  newFootOk(int x,int y, int type);
int playChess(int x,int y ,int tag);

int main(){

		int i,j;
		
		for(i=0;i<head;i++){
			
			for(j=0;j<head;j++){
				
				palace[i][j]=0;
			}
		}
		palace[2][0]=1;
		playChess(2,0,2);

		printf("it count:%d\n",count);







	return 0;
}

int playChess(int x,int y ,int tag){
	int i,j;
	if(tag == 17){

			count++;

			for(i=0;i<head;i++){

				for(j=0;j<head;j++){

					printf("%d ",palace[i][j]);
					if(j == head-1){

						printf("\n");
					}
				}
			}


	}
	int oldX,oldY;
	for(i=0;i<head;i++){


		if(newFootOk(x,y,i)){
			oldX=newX;
			oldY=newY;
			palace[oldX][oldY]=tag;
			playChess(oldX,oldY,tag+1);
			palace[oldX][oldY]=0;

		}
	}








}

int  newFootOk(int x,int y, int type){
		
		
		switch(type){
		case 0:
			
			if((x-2) >=0 && (y-1) >=0 && palace[x-2][y-1]==0){
				
				newX=x-2;
				newY=y-1;
				return true;
			}
			
			
			break;
		case 1:
			
			 if((x-1) >= 0 && (y-2) >= 0 && palace[x-1][y-2]== 0){
				 
				 
				 newX =x-1;
				 newY =y-2;
				 
				 return true;
			 }
			
			break;
		case 2:
			if((x+1) < head && (y-2) >= 0 && palace[x+1][y-2] == 0){
				
				
				newX = x+1;
				newY = y-2;
				return true;
			}
			
			break;
		case 3:
			if((x+2) <  head && (y-1) >= 0 && palace[x+2][y-1] == 0){
				
				
				newX = x+2;
				newY = y-1;
				
				return true;
			}
			
			break;
		case 4:
			if((x-2) >= 0 && (y+1) < head && palace[x-2][y+1] == 0){
				
				newX = x-2;
				newY = y+1;
				
				return true;
			}
			
			break;
			
		case 5:
			if((x-1) >=0 && (y+2) < head && palace[x-1][y+2] == 0){
				
				newX = x-1;
				newY = y+2;
				
				return true;
			}
			
			break;
		case 6:
			
			if((x+1) < head && (y+2) < head && palace[x+1][y+2] == 0){
				
				newX = x+1;
				newY = y+2;
				return true;
			}
			
			
			break;
		case 7:
			if((x+2) < head && (y+1) < head && palace[x+2][y+1] == 0){
				
				newX = x+2;
				newY = y+1;
				
				
				return true;
			}
			
			break;
		
			default:
				
				break;
		
		}
		return false;
		
	}